//
//  UIButtonItem+Extension.swift
//  WeiBo
//
//  Created by gzy on 2017/10/24.
//  Copyright © 2017年 GZY. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title:      title
    ///   - fontSize:   fontSize 默认 16 号
    ///   - target:     target
    ///   - action:     action
    ///   - isBack:     是否是返回按钮
    convenience init(title:String, fontSize: CGFloat = 16,target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.zy_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBack {
            let imageNamed = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageNamed), for: .normal)
            btn.setImage(UIImage(named:imageNamed + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        btn .addTarget(target, action: action, for: .touchUpInside)
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
